﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using FwProject.Controllers;
using FwProject.Pay;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Hosting;
using FwProject.Configuration;
using FwProject.ShoppingMall.Com;
using Microsoft.AspNetCore.Mvc;

[Route("api/[controller]/[action]")]
    public class PayAsyncMenberController : FwProjectControllerBase
    {
        private readonly IPayPayAppService _payPayAppService;
        private readonly IConfigurationRoot _appConfiguration;
        private readonly IHostingEnvironment _env;

        public PayAsyncMenberController(IPayPayAppService payPayAppService, IHostingEnvironment env)
        {
            _payPayAppService = payPayAppService;
            _env = env;
            _appConfiguration = _env.GetAppConfiguration();
        }
    /// <summary>
    /// 支付宝支付成功通知
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    public async Task AlaiPayAsyncNotify()
        { 
            // #if DEBUG
            //       bool test  = _payPayAppService.TestAlipayCheckPay(PayType.支付宝支付,Request.Query["OrderNumber"]);
            //    if(test)
            //       await Response.WriteAsync("success");
            //else
            //    await Response.WriteAsync("fail");
            // #endif

         
            bool success=  _payPayAppService.PayPayNotify(PayType.支付宝支付);
            if (success)
            {
                  await Response.WriteAsync("success");
            }
            else {
                await Response.WriteAsync("fail");

            }
               
        }
    /// <summary>
    /// 支付宝支付成功通知
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    public async Task WeixinPayAsyncNotify()
        {


          #if DEBUG
            //bool test = _payPayAppService.TestAlipayCheckPay(PayType.微信支付, Request.Query["OrderNumber"]);
            //if (test)
            //    await Response.WriteAsync("success");
            //else
            //    await Response.WriteAsync("fail");
           #endif

            bool success = _payPayAppService.PayPayNotify(PayType.微信支付);
            if (success)
            {
                    await Response.WriteAsync("success");
            }
            else
            {
                await Response.WriteAsync("fail");

            }

        }



    //private Dictionary<string, string> GetRequestPost()
    //{
    //    int i = 0;
    //    Dictionary<string, string> sArray = new Dictionary<string, string>();
    //    // NameValueCollection coll;
    //    //Load Form variables into NameValueCollection variable.

    //    // Get names of all forms into a string array.
    //    String[] requestItem = Request.Form.Keys.ToArray();

    //    for (i = 0; i < requestItem.Length; i++)
    //    {
    //        sArray.Add(requestItem[i], Request.Form[requestItem[i]]);
    //    }

    //    return sArray;
    //}
}

